var mysql      = require('mysql');


function poolInit(){
  var new_pool = mysql.createPool({
    connectionLimit : 10,
    host      :"localhost",
    user      :"root",
    password    :"123456",
    database    :"test"
  });  
  return new_pool;
}

function poolClose(pool){
  if(typeof pool != "undefined" && pool){
    pool.destory();
  }
}

var pool = poolInit();

exports.getConn = function(callback_function){
  pool.getConnection(function(err,new_conn){
    init();
    callback_function(err,new_conn);
  })
}

exports.init = init = function (new_pool) {
  if(typeof new_pool != "undefined"){
    poolClose(pool);
    pool = poolInit();
  }
  return pool;
}